let Router = require('koa-router')
let router = new Router()

router.get('/mock/test', async (ctx, next) => {
    ctx.body = {
        'hello': 'helloworld',
        'aaa': 20,
        'isgeted': true,
    }
})

function stringRandom(n = 24, chars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']) {
    var res = "";
    for (var i = 0; i < n; i++) {
        var id = Math.ceil(Math.random() * 35);
        res += chars[id];
    }
    return res;
}
let random = (length) => {
    return Math.floor(Math.random() * length)
}
let getYearMonthDay = () => {
    let theDate = new Date()
    let year = theDate.getFullYear()
    let month = theDate.getMonth()
    let day = theDate.getDay()
    return year + month + day
}

let createCarList = (num) => {
    let carlist = new Array()
    for (let i = 0; i < num; i++) {
        let str = ''
        let MA_ORDERITEM = {
            ID: stringRandom(8),              //* ID
            ORDERCODE: 'CQ' + stringRandom(8),       //* 订单项流水号
            PRODUCTCODE: 'PJNS' + stringRandom(8),     //* 产品编号
            USERID: 'USER' + stringRandom(8),          //* 会员ID
            PRICE: [460, 1180, 4680][random(3)],            //单价
            SAMPLINGMETHOD: [0, 1][random(2)],   //取样方式 0:自取样；1:预约取样默认：0
            STATUS: [0, 1, 2][random(3)],
            // STATUS: [0,1,2,3,4,5,6,7,8,9,'T','Z','S','F','C','P'][random(16)],           //订单项状态(0: 未支付，1:已支付，2:未安排取样，3:安排取样中（已发放采样器），4:已绑定样本，5:样本已回递，6:样本入库，7:检测中，8:已出报告，9:未出报告，T:退款 ,Z:重检测，S:重采样，F:检测失败，C:样本编号冲突，P:推送失败)
            INTEGRAL: random(300),         //积分
            ORDERTYPE: [0, 1][random(2)],        //订单类型 0:服务检测订单；1:咨询订单; 默认：0
            REMARKS: '',         //备注
            SERVICER: '',        //服务人员
            TASKSFLAG: [0, 1][random(2)],        //任务指定标志 0:未匹配；1:已匹配, 默认：0
            ITEM_COUNT: '',      //数量
            ORDER_ID: '',        //订单ID
            ORDERDATE: new Date(),       //下订单日期
            OLD_ORDERITEM_IDN: '',       //原订单项id
            TESTTYPE: [0, 1, 2, 3, 4, 5, 6][random(7)],         //检测类别 01首次筛查、02二次筛查、03三次筛查、04四次筛查、05复查、06重检测
            //添加的类型
            NAME: ['林细雨', '王蛋蛋', '李芬'][random(3)], //用户的姓名
            SERVERTYPE: [0, 1, 2][random(3)], //0=3年保障, 1=9年保障, 3=终身保障
            PAYDATA: ['今天 12:30', '昨天 16:45', '昨天 02:45', '2017年5月3日'][random(4)], //支付时间
        }
        carlist.push(MA_ORDERITEM)
    }
    return carlist
}


router.get('/wechat/manage/queryOrderProduct', async (ctx, next) => {
    let id = ctx.request.body.id
    console.log(id)
    ctx.body = { list: createCarList(4) }
})

module.exports = router